<%@page contentType="text/html;charset=UTF-8"%>
<%@page pageEncoding="UTF-8"%>
<%@ include file="/pub/includ.jsp"%>
<%@ page import="com.wing.common.util.ApplicationPath,com.wing.common.Constants" %>
<%String userId = (String)request.getSession().getAttribute(Constants.SESSION_USER_ID);%>
<html>
	<head>
		<script type="text/javascript">
			$(function() {
		     	loadGird("frm", 1);
		    });
		
			
			var callback_frm = function(rows, frm) {
		       $.each(rows, function(i, n){
		    	   var row = $("#"+frm+" .template").clone().removeClass("template");
		   	       var keyValue = n.id;
			       row.find(".klId").attr("value",n.id);
			   	
			       row.find(".klsite_name").html("<a target='_blank' href='http://"+n.site_url+"'>"+n.site_name+"</a>");
			   	
			       row.find(".klsite_path").text(n.site_path);
			   	
			       row.find(".klsite_url").html("<a target='_blank' href='http://"+n.site_url+"'>"+n.site_url+"</a>");
			   	
			       row.find(".klorder_num").text(n.order_num);
		 
		 		   row.attr("id","ready"+i);
		           row.attr("class","tr_nbw");
		           row.appendTo("#"+frm+" .grid");
		       });   
			}
			
			var delsites = function(){
				var options = {
				type: 'POST',
				async: false,
				dataType: 'content-type',
				success: function(msg) {
					alert("成功删除"+msg+"个站点。");
					document.location.reload();
				}
				}
				if(confirm('您确认要删除吗？')){
					document.getElementById("frm").action="<%=path%>/cms/site/delsites";
					$('#frm').ajaxSubmit(options);
				}
			}
			
			
			function addsites(){
				opendailog("{src:'<%=path %>/cms/site/toForm/0',title:'站点属性',width:500,height:300,savefunc:'savefunc'}",window);
			}
			
			function modifysites(){
				if(checkOnlySel()){
		            opendailog("{src:'<%=path %>/cms/site/toForm/"+getCheckedObj("chk")[0].value+"',title:'站点属性',width:500,height:300,savefunc:'savefunc'}",window);
	            }
			}
			
			function cloneSite(){
				if(checkOnlySel()){
		            opendailog("{src:'<%=path %>/cms/site/toClone/"+getCheckedObj("chk")[0].value+"',title:'站点复制',width:500,height:300,savefunc:'savefunc2'}",window);
	            }
			}
	
			function savefunc2(frame){
				var retv = frame.contentWindow.save()
				if(retv=="success"){
			   		alert("复制完成");
			   		loadGird("frm", 1);
				}
				if(retv=="domainrepeat"){
					alert("站点路径重复！");
				}
				return retv;
			}
			
			function bakSite(){
				if(checkOnlySel()){
					$.ajax({
						   type: "POST",
						   url: "<%=path %>/cms/site/bakSite?siteId="+getCheckedObj("chk")[0].value,
						   error: function(){
						   		alert("备份失败～");
						   },
						   success: function(){
						   		alert("备份成功～");
						   }
					});	
		        }	
			}
			
			function indexSite(){
				if(checkOnlySel()){
					$.ajax({
						   type: "POST",
						   url: "<%=path %>/cms/site/indexSite?siteId="+getCheckedObj("chk")[0].value,
						   error: function(){
						   		alert("索引失败～");
						   },
						   success: function(){
						   		alert("索引成功～");
						   }
					});	
		        }	
			}
			function savefunc(frame){
				var retv = frame.contentWindow.save()
				if(retv=="success"){
					alert("保存成功！");
					reloadGrid("frm", 1);
				}
				if(retv=="domainrepeat"){
					alert("站点路径重复！");
				}
				return retv;
			}
			
			function modSiteAuths(){
				if(checkOnlySel()){
					opendailog("{src:'<%=path %>/cms/site/toAuth/"+getCheckedObj("chk")[0].value+"',title:'站点授权',width:600,height:300,savefunc:'authfunc'}",window);
	            }
			}
			function authfunc(frame){
				frame.contentWindow.save();
				return "success";
			}
			
			function search(){
				$("#seachv").val($("#searchval").val());
				loadGird("frm");
			}
		</script>
	</head>
	<body style="background-color: transparent"><div style="text-align:center"></div>
		<table width="100%">
			<tr>
				<td height="2px" colspan="2"></td>
			</tr>
			<tr>
				<td >&nbsp;&nbsp;&nbsp;
					<input type="text" id="searchval" value="">
					<input type="button" onclick="search();" class="button4_nbw" value="搜索" />
				</td>
			<td align="right">
			<input type="button" onclick="addsites();" class="button4_nbw" value="添加" />
			<input type="button" onclick="modifysites();" class="button4_nbw" value="修改" />
			<input type="button" onclick="delsites()" class="button4_nbw" value="删除" />
			<input type="button" onclick="modSiteAuths();" class="button4_nbw" value="授权" />
			<input type="button" onclick="bakSite();" class="button4_nbw" value="备份" />
			<input type="button" onclick="cloneSite();" class="button4_nbw" value="复制" />
			<input type="button" onclick="indexSite();" class="button4_nbw" value="索引" />
			&nbsp;&nbsp;
			</td></tr>
		</table>
	<form name="frm" method="post" style="margin: 0" action="<%=path%>/cms/site/list" id="frm">
		<input type="hidden" id="seachv" name="seachv" value="">
		<center>
		<table><tr><td height="2px"></td></tr></table>
		<table border="0" cellspacing="1" cellpadding="0" class="table_nbw  niceTable grid">
			<thead class="th_nbw">
				<tr >
					<td width="40px" height="30px">
						<input type="checkbox" class="allCheck" />
					</td>
		      		<td width="40%">
						站点名称
					</td>   
		      		<td>
						站点路径
					</td>   
		      		<td>
						站点URL
					</td>   
		      		<td width="10%">
						排序号
					</td>   
				</tr>
			</thead>
			<tbody>
				<tr class="template klId" >
					<td width="40px" class="idCheck">
						<input type="checkbox" name="chk" class="klId" />
					</td>
		   		    <td class="klsite_name niceTable-left"></td>
		   		    <td class="klsite_path niceTable-left"></td>
		   		    <td class="klsite_url niceTable-left"></td>
		   		    <td  width="10%" class="klorder_num "></td>
				</tr>
			</tbody>
			<tfoot>
				<tr>
					<td style="border-right: none">
						<img class="loading"
							src="<%=path %>/resources/skins/default/images/large-loading.gif" width="20px"
							class="hidden" />
					</td>
					<td colspan="4" style="border-left: none" class="txtRight">
						<span class="pagediv"></span>
					</td>
				</tr>
			</tfoot>
		</table>
		</center>
	</form>
</body>
</html>
